/**
 * 
 */
package com.laozhao.deliveryManager.business;

import java.sql.SQLException;
import java.sql.Statement;

import com.laozhao.deliveryManager.model.entity.TransDeliveryMain;
import com.laozhao.deliveryManager.model.view.DeliveryDocView;
import com.laozhao.deliveryManager.util.Constant;
import com.laozhao.deliveryManager.util.ToolsUtil;
import com.laozhao.dreamframe.dbmanager.DBFactory;
import com.laozhao.dreamframe.dbmanager.DataBaseManager;

/**
 * @author laozhao
 *
 */
public class MasterServer extends AbstractServer {

	
	/**
	 * 
	 */
	public MasterServer() {
		super.init();
	}
	
	public void saveDeliveryOrder(DeliveryDocView deliveryDoc){
		if (deliveryDoc != null 
				&& deliveryDoc.getMainDoc() != null
				&& deliveryDoc.getDetails() != null) {

//			StringBuffer sqlBuffer = new StringBuffer();
			String sql ;
			try {
				DataBaseManager manager = DBFactory.getInstance();
//				conn.setAutoCommit(false);
//				Statement statement = conn.createStatement();
				// insert delivery main
//				TransDeliveryMain mainDoc = deliveryDoc.getMainDoc();
//				sql = "Insert Into DELIVERY_MAIN ( CUSTOMER_ID , CUSTOMER_NAME ,  CUSTOMER_ADDRESS ,  DELIVERY_NO , SEND_DATE , AMOUNT , SEND_USER ,  STATUS , CREATE_BY , CREATE_ON , MODIFY_BY , MODIFY_ON , DEL_FLG ) Values ( ':CUSTOMER_ID' , ':CUSTOMER_NAME' ,  ':CUSTOMER_ADDRESS' ,  ':DELIVERY_NO' , ':SEND_DATE' , ':AMOUNT' , ':SEND_USER' ,  ':STATUS' , ':CREATE_BY' , ':CREATE_ON' , ':MODIFY_BY' , ':MODIFY_ON' , ':DEL_FLG')";
//				sql.replace(":CUSTOMER_ID",mainDoc.getCustomer()== null ? "0" : mainDoc.getCustomer().getId().toString());
//				sql.replace(":CUSTOMER_NAME",mainDoc.getCustomerName()== null ? "" : mainDoc.getCustomerName());
//				sql.replace(":CUSTOMER_ADDRESS",mainDoc.getCustomerAddress()== null ? "" : mainDoc.getCustomerAddress());
//				sql.replace(":DELIVERY_NO",mainDoc.getDelNo()== null ? "" : mainDoc.getDelNo());
//				sql.replace(":SEND_DATE",mainDoc.getSendDate() == null ? "0" : ToolsUtil.dateToString(mainDoc.getSendDate()));
//				sql.replace(":AMOUNT",mainDoc.getAmount() == null ? "0" : mainDoc.getAmount().toString());
//				sql.replace(":SEND_USER",mainDoc.getUser()== null ? "0" : mainDoc.getUser());
//				sql.replace(":STATUS",Constant.DELIVERY_DEFAULT);
//				
////				BaseInsert sel = new BaseInsert("insert INTO sys_sql ( $columnset ) values ( $valueset )",map);
////				String sql= sel.toSql();
//				if (sql !=null) {
//					DataBaseManager.execute(sql);
//				}
				manager.commit();
				manager.closeConnection();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
	
	
}
